#include"Game.h"
#include<ctime>

//Start game
void start(){
	Game.start();
}
//Hien thi texture
void display(){
	Game.display();
}

//Thiet lap keyboard
void keyboard(unsigned char button, int, int){
	Game.Keyboard(button);
}

void keyboard(int key, int, int){
	Game.Keyboard(key);
}
void motion(int x, int y){
	Mouse.Init(x, y);
}

void passive(int x, int y){
	Mouse.Init(x, y);
}
//Khoi tao man hinh
void initialize(){
    glutInitDisplayMode (GLUT_DOUBLE | GLUT_DEPTH | GLUT_RGB);
    glutInitWindowSize(WIDTH, HEIGHT);
    glutInitWindowPosition(glutGet(GLUT_SCREEN_WIDTH) / 2 - WIDTH / 2, glutGet(GLUT_SCREEN_HEIGHT) / 2 - HEIGHT / 2);
    glutCreateWindow("Nguyen_Van_Thang_GLTest");
    glClearColor(1, 1, 1, 1);
    glMatrixMode(GL_PROJECTION);
	glutSetCursor(GLUT_CURSOR_NONE);
    glLoadIdentity();
    glOrtho(-WIDTH / 2, WIDTH / 2, -HEIGHT / 2, HEIGHT / 2 , -1, 1);
}
//THiet lap thoi gian cho timer
void timer(int = 0)
{
	Game.Timer();
	display();
    glutPostRedisplay();
    glutTimerFunc(10, timer, 0);
}

//Thiet lap cac ham vao opengl
void functions(){
    glutDisplayFunc(display);
	glutMotionFunc(motion);
	glutPassiveMotionFunc(passive);
	glutSpecialFunc(keyboard);
	glutKeyboardFunc(keyboard);
	timer();
}

//Ham main
int main(int argc, char** argv)
{
	srand(time(0));
	glutInit(&argc, argv);
	initialize();
	loadTextures();
	functions();
	start();
	glutMainLoop();
	glEnd();
	return 0;
}